package com.qqs.distributed.service;

import com.qqs.distributed.annotation.Cache;
import com.qqs.distributed.bean.Dog;
import java.util.ArrayList;
import java.util.List;

public class DogService {
    @Cache(ttl = 300000,cacheKeyExpr = "#")
    public String call() {
        return "dog6666";
    }

    @Cache(ttl = 300000)
    public Dog igang() {
        Dog dog = new Dog();
        dog.setId(1001);
        dog.setAge(18);
        dog.setName("igang");
        List<Dog.Person> ps = dog.getPs();
        for (int i = 0; i < 5; i++) {
            Dog.Person person = new Dog.Person();
            person.setpId(2000 + i);
            person.setpAge(100 + i);
            person.setpName("igang tom" + i);
            ps.add(person);
        }
        return dog;
    }

    @Cache(ttl = 300000)
    public List<Dog> igang2() {
        ArrayList<Dog> dogs = new ArrayList<>();
        for (int j = 0; j < 3; j++) {
            Dog dog = new Dog();
            dog.setId(1001 + j);
            dog.setAge(18 + j);
            dog.setName("igang" + j);
            List<Dog.Person> ps = dog.getPs();
            for (int i = 0; i < 5; i++) {
                Dog.Person person = new Dog.Person();
                person.setpId(2000 + i * j);
                person.setpAge(100 + i * j);
                person.setpName("igang tom" + i * j);
                ps.add(person);
            }
            dogs.add(dog);
        }
        return dogs;
    }

    @Cache(ttl = 300000)
    public <T> T igang3(Class<T> returnType) {
        Dog dog = igang();
        return (T) dog;
    }

    @Cache(ttl = 300000)
    public <T> T igang4(Class<T> returnType) {
        ArrayList<Dog> dogs = new ArrayList<>();
        for (int j = 0; j < 3; j++) {
            Dog dog = new Dog();
            dog.setId(1001 + j);
            dog.setAge(18 + j);
            dog.setName("igang" + j);
            List<Dog.Person> ps = dog.getPs();
            for (int i = 0; i < 5; i++) {
                Dog.Person person = new Dog.Person();
                person.setpId(2000 + i * j);
                person.setpAge(100 + i * j);
                person.setpName("igang tom" + i * j);
                ps.add(person);
            }
            dogs.add(dog);
        }
        return (T) dogs;
    }
}
